{% extends "account/base.html" %}
{% load features %}

{% block content %}
	<section id="account-api" class="box-section">
		<h3>Authentication Tokens</h3>
		<div class="inner">
		{% if not tokens.count %}
			<p>
				You do not have any upload client associated with your account.
				<a href="{% url 'downloads' %}">Download Hearthstone Deck Tracker</a> and
				claim your account from there!
			</p>
		{% else %}
			<p>The following tokens can be used to upload your games. Keep them private!</p>
			<table class="table table-bordered">
				<thead>
					<th>Application</th>
					<th>Token</th>
					<th>Created on</th>
				</thead>
			{% for token in tokens %}
				<tr>
					{% if token.creation_apikey.website %}
						<td><a href="{{ token.creation_apikey.website }}">{{ token.creation_apikey }}</a></td>
					{% else %}
						<td>{{ token.creation_apikey }}</td>
					{% endif %}
					<td>{{ token }}</td>
					<td>{{ token.created }}</td>
				</tr>
			{% endfor %}
			</table>
		{% endif %}
		</div>
	</section>

	{% feature "webhooks" %}
	<section id="account-webhooks" class="box-section">
		<h3>Webhooks</h3>
		<div class="inner">
			<p>
				Webhooks allow you, or an authorized application, to automatically POST to a URL
				whenever you complete a game and it is made available on HSReplay.net.
			</p>

			<p class="alert alert-warning">
				<strong>This feature is still in beta.</strong><br/>
				The API objects are not final and the functionality is still being tested.
				If you are interested in using them or have any questions,
				<a href="mailto:help@hsreplay.net">please contact us</a> so we can help!
			</p>

			{% if not webhooks.count %}
				<p>
					You don't have any webhooks set up right now.
				</p>
			{% else %}
				<table class="table table-bordered">
					<thead>
						<th>UUID</th>
						<th>URL</th>
						<th>Created</th>
						<th>Active</th>
					</thead>
					{% for webhook in webhooks %}
						<tr>
							<td><a href="{{ webhook.get_absolute_url }}">{{ webhook.uuid }}</a></td>
							<td>{{ webhook.url }}</td>
							<td>{{ webhook.created.isoformat }}</td>
							{% if webhook.is_active %}
								<td class="webhook-active">✓</td>
							{% else %}
								<td class="webhook-inactive">✗</td>
							{% endif %}
						</tr>
					{% endfor %}
				</table>
			{% endif %}

			<a href="{% url 'account_new_webhook' %}" class="btn btn-info">Add webhook…</a>
		</div>
	</section>
	{% endfeature %}
{% endblock %}
